using System;
using System.Collections.Generic;
using System.Data;
using System.Configuration;
using System.Collections;
using System.IO;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Doc.Xroad.Eu;
 
using Xtee.XteeClient.Doc;
 

namespace DocumentClient
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           
           
            
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            var filename = Path.Combine(new DocAdapter().XteeCommand.Configuration.Storage.MainRoot,
                                        FileUpload1.FileName);
            FileUpload1.SaveAs(filename);
            string friendlyname = tbFriendlyName.Value;


            new DocAdapter().AddDocument(new Document(friendlyname, new FileInfo(filename)));
            Response.Write("File Sent : " + filename);

          
            
           
        }

        protected void btGetdoc_Click(object sender, EventArgs e)
        {
            string friendlyname = txGetFriendlyDocName.Value;

            FileInfo receivedFile = new DocAdapter().GetDocument(friendlyname).Document.Sisu;
            Response.Write("Received file : "+receivedFile.FullName);
        }

        protected void btGetAvailableFiles_Click(object sender, EventArgs e)
        {
          var getDocumentListResponse =   new DocAdapter().GetDocumentList();
            lbFileList.Items.Clear();
          foreach (var alldoc in getDocumentListResponse.AllDocuments)
          {
              this.lbFileList.Items.Add(alldoc.Name);

          }
          lbDocumentsOnServer.Text = "Documents on server (" + this.lbFileList.Items.Count.ToString() + ")";
        }

        
        protected void lbFileList_SelectedIndexChanged(object sender, EventArgs e)
        {

            txGetFriendlyDocName.Value = lbFileList.SelectedValue;
        }

       
    }
}
